.TH std::chrono::zoned_time::zoned_time 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::chrono::zoned_time::zoned_time \- std::chrono::zoned_time::zoned_time

.SH Synopsis
   zoned_time();                                                     \fB(1)\fP  \fI(since C++20)\fP
   zoned_time( const std::chrono::sys_time<Duration>& st );          \fB(2)\fP  \fI(since C++20)\fP
   zoned_time( const zoned_time& other ) = default;                  \fB(3)\fP  \fI(since C++20)\fP
   template< class Duration2 >
   zoned_time( const std::chrono::zoned_time<Duration2,              \fB(4)\fP  \fI(since C++20)\fP
   TimeZonePtr>& other );
   explicit zoned_time( TimeZonePtr z );                             \fB(5)\fP  \fI(since C++20)\fP
   explicit zoned_time( std::string_view name );                     \fB(6)\fP  \fI(since C++20)\fP
   zoned_time( TimeZonePtr z, const std::chrono::sys_time<Duration>& \fB(7)\fP  \fI(since C++20)\fP
   st );
   zoned_time( std::string_view name, const                          \fB(8)\fP  \fI(since C++20)\fP
   std::chrono::sys_time<Duration>& st );
   zoned_time( TimeZonePtr z, const                                  \fB(9)\fP  \fI(since C++20)\fP
   std::chrono::local_time<Duration>& tp );
   zoned_time( std::string_view name, const                          \fB(10)\fP \fI(since C++20)\fP
   std::chrono::local_time<Duration>& tp );
   zoned_time( TimeZonePtr z, const
   std::chrono::local_time<Duration>& tp,                            \fB(11)\fP \fI(since C++20)\fP
               std::chrono::choose c );
   zoned_time( std::string_view name,
               const std::chrono::local_time<Duration>& tp,          \fB(12)\fP \fI(since C++20)\fP
   std::chrono::choose c );
   template< class Duration2, class TimeZonePtr2 >

   zoned_time( TimeZonePtr z,                                        \fB(13)\fP \fI(since C++20)\fP

               const std::chrono::zoned_time<Duration2,
   TimeZonePtr2>& zt );
   template< class Duration2, class TimeZonePtr2 >

   zoned_time( TimeZonePtr z,
               const std::chrono::zoned_time<Duration2,              \fB(14)\fP \fI(since C++20)\fP
   TimeZonePtr2>& zt,

               std::chrono::choose );
   template< class Duration2, class TimeZonePtr2 >

   zoned_time( std::string_view name,                                \fB(15)\fP \fI(since C++20)\fP

               const std::chrono::zoned_time<Duration2,
   TimeZonePtr2>& zt );
   template< class Duration2, class TimeZonePtr2 >

   zoned_time( std::string_view name,
               const std::chrono::zoned_time<Duration2,              \fB(16)\fP \fI(since C++20)\fP
   TimeZonePtr2>& zt,

               std::chrono::choose );

   Constructs a zoned_time object, initializing the stored time zone pointer and time
   point according to the following table, where traits is
   std::chrono::zoned_traits<TimeZonePtr>:

   Overload Time zone pointer (denoted               Time point (a                Notes
                      zone)                 std::chrono::sys_time<duration>)
   \fB(1)\fP      traits::default_zone()     default constructed                        (a)
   \fB(2)\fP                                 st
   \fB(3)\fP      other.get_time_zone()      other.get_sys_time()                       (b)
   \fB(4)\fP      other.get_time_zone()      other.get_sys_time()                       (e)
   \fB(5)\fP      std::move(z)               default constructed
   \fB(6)\fP      traits::locate_zone(name)                                             (c)
   \fB(7)\fP      std::move(z)               st
   \fB(8)\fP      traits::locate_zone(name)                                             (c)
   \fB(9)\fP      std::move(z)               zone->to_sys(tp)                           (d)
   \fB(10)\fP     traits::locate_zone(name)                                             (c,d)
   \fB(11)\fP     std::move(z)               zone->to_sys(tp, c)                        (d)
   \fB(12)\fP     traits::locate_zone(name)                                             (c,d)
   (13,14)  std::move(z)               zt.get_sys_time()                          (e)
   (15,16)  traits::locate_zone(name)                                             (c,e)

   a) Constructors specified to call traits::default_zone() (1,2) do not participate in
   overload resolution if that expression is not well-formed.
   b) The defaulted copy constructor \fB(3)\fP is defined as deleted if
   std::is_copy_constructible_v<TimeZonePtr> is false.
   c) Constructors with a std::string_view parameter name (6,8,10,12,15,16) do not
   participate in overload resolution if traits::locate_zone(name) is not well-formed
   or if that expression is not convertible to TimeZonePtr.
   d) Constructors specified to call zone->to_sys (9-12) do not participate in overload
   resolution if that call expression is not well-formed or if the result is not
   convertible to std::chrono::sys_time<duration>.
   e) Constructors with a template parameter Duration2 (4,13-16) do not participate in
   overload resolution if Duration2 is not convertible to Duration.

   The behavior is undefined if the time zone pointer (initialized as described above)
   does not refer to a time zone.

.SH Notes

   zoned_time does not have a move constructor and attempting to move one will perform
   a copy instead using the defaulted copy constructor \fB(3)\fP. Thus, when TimeZonePtr is a
   move-only type, zoned_time is immovable: it can be neither moved nor copied.

   The constructors (14,16) accept a std::chrono::choose parameter, but that parameter
   has no effect.

.SH Example


// Run this code

 #include <chrono>
 #include <iostream>
 #include <string_view>

 int main()
 {
     using std::chrono_literals::operator""y;
     using std::operator""sv;

     std::cout << std::chrono::zoned_time{} << " : default\\n";

     constexpr std::string_view location1{"America/Phoenix"sv};
     std::cout << std::chrono::zoned_time{location1} << " : " << location1 << '\\n';

     const std::chrono::time_zone* timeZonePtr = std::chrono::locate_zone("UTC");
     std::cout << std::chrono::zoned_time{timeZonePtr} << " : UTC time zone\\n";

     constexpr auto location2{"Europe/Rome"sv};
     std::cout << std::chrono::zoned_time{location2, std::chrono::local_days{2021y/12/31}}
               << " : " << location2 << '\\n';

     constexpr auto location3{"Europe/Rome"sv};
     constexpr auto some_date = std::chrono::sys_time<std::chrono::days>{2021y/12/31};
     std::cout << std::chrono::zoned_time{location3, some_date}
               << " : " << location3 << '\\n';

     const auto now =
         std::chrono::floor<std::chrono::minutes>(std::chrono::system_clock::now());
     constexpr auto location4{"Europe/Rome"sv};
     std::cout << std::chrono::zoned_time{location4, now} << " : " << location4 << '\\n';

     constexpr auto NewYork{"America/New_York"sv};
     constexpr auto Tokyo{"Asia/Tokyo"sv};
     const std::chrono::zoned_time tz_Tokyo{Tokyo, now};
     const std::chrono::zoned_time tz_NewYork{NewYork, now};
     std::cout << std::chrono::zoned_time{Tokyo, tz_NewYork} << " : " << Tokyo << '\\n';
     std::cout << std::chrono::zoned_time{NewYork, tz_Tokyo} << " : " << NewYork << '\\n';
 }

.SH Possible output:

 1970-01-01 00:00:00 UTC : default
 1969-12-31 17:00:00 MST : America/Phoenix
 1970-01-01 00:00:00 UTC : UTC time zone
 2021-12-31 00:00:00 CET : Europe/Rome
 2021-12-31 01:00:00 CET : Europe/Rome
 2021-09-20 23:04:00 CEST : Europe/Rome
 2021-09-21 06:04:00 JST : Asia/Tokyo
 2021-09-20 17:04:00 EDT : America/New_York
